// 滚动时改变导航栏样式
window.addEventListener('scroll', function() {
    const header = document.querySelector('header');
    if (window.scrollY > 50) {
        header.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
    } else {
        header.style.backgroundColor = '#fff';
    }
});

// 平滑滚动到锚点
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({
                behavior: 'smooth'
            });
        }
    });
});

// 文章卡片动画
const postCards = document.querySelectorAll('.post-card');
postCards.forEach(card => {
    card.addEventListener('mouseenter', () => {
        card.style.transform = 'translateY(-10px)';
    });
    
    card.addEventListener('mouseleave', () => {
        card.style.transform = 'translateY(0)';
    });
});

let lastScrollY = window.scrollY;
let ticking = false;

// 处理导航栏的显示和隐藏
function updateNav() {
    const header = document.querySelector('header');
    const currentScrollY = window.scrollY;

    // 向下滚动时隐藏导航栏，向上滚动时显示导航栏
    if (currentScrollY > lastScrollY) {
        header.classList.add('nav-hidden');
    } else {
        header.classList.remove('nav-hidden');
    }

    lastScrollY = currentScrollY;
    ticking = false;
}

// 监听滚动事件
window.addEventListener('scroll', () => {
    if (!ticking) {
        window.requestAnimationFrame(() => {
            updateNav();
        });
        ticking = true;
    }
}); 